package com.celeste.sms.main;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import com.celeste.sms.client.PushServerWSStub;
import com.clickatell.api.soap.webservice.AuthDocument;
import com.clickatell.api.soap.webservice.AuthResponseDocument;
import com.clickatell.api.soap.webservice.PingDocument;
import com.clickatell.api.soap.webservice.PingResponseDocument;
import com.clickatell.api.soap.webservice.AuthResponseDocument.AuthResponse;
import com.clickatell.api.soap.webservice.PingResponseDocument.PingResponse;

public class SMSMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {	
		try {
			PushServerWSStub stub = null;
			try{
			 //stub = new PushServerWSStub();
				stub = new PushServerWSStub();
			}catch(Exception e){
				System.out.print("Error al crear el cliente");
				e.printStackTrace();
			}

			AuthDocument authDocument = AuthDocument.Factory.newInstance();
			AuthDocument.Auth auth = authDocument.addNewAuth();
			// Ading parameters
			auth.setApiId(3353447);
			auth.setUser("condominio");
			auth.setPassword("Sms@1234");

			AuthResponseDocument resp = stub.auth(authDocument);
			AuthResponse authResponse = resp.getAuthResponse();
			
			String session = authResponse.getReturn().replace("OK: ", "");
			System.out.println("Resultado: " + session);
			
			//Haciendo Ping
            PingDocument pingDocument = PingDocument.Factory.newInstance();
            PingDocument.Ping ping = pingDocument.addNewPing();
            //Agregando parametros
            ping.setSessionId(session);
            PingResponseDocument pingResponseDocument = stub.ping(pingDocument);
            PingResponse pingResponse = pingResponseDocument.getPingResponse();
            System.out.print("Ping Response " + pingResponse.getReturn());
			
		} catch (AxisFault e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
